package mt;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author zhangmin
 * @create 2022-03-19 11:29
 */
public class meituan_0319_Main_4 {
    int maxsum;
    int k2;
    LinkedList<LinkedList<Integer>> res=new LinkedList<>();
    int k1;
    void backtrack(int[] val, int index, LinkedList<Integer> path, int sum){

        if(path.size()!=0&&sum%k1==0&&sum%k2!=0){
            maxsum=Math.max(maxsum,sum);
            res.add(new LinkedList<>(path));
            //return;
        }
        if(index>=val.length) return;
        path.add(val[index]);
        backtrack(val,index+1,path,sum+val[index]);
        path.removeLast();
        backtrack(val,index+1,path,sum);
    }
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int k1=cin.nextInt();
        int k2=cin.nextInt();
        int[] val=new int[n];
        for (int i = 0; i < n; i++) {
            val[i]=cin.nextInt();
        }
        meituan_0319_Main_4 obj=new meituan_0319_Main_4();
        obj.maxsum=Integer.MIN_VALUE;
        obj.k1=k1;
        obj.k2=k2;

        obj.backtrack(val,0,new LinkedList<>(),0);
        System.out.println(obj.res);
        System.out.println(obj.maxsum+" "+ obj.res.size());
    }
}
